package Dominio.Entidades;

import java.io.Serializable;

public class Coordenada implements Serializable, Comparable<Coordenada> {

    private int posFila;
    private int posColumna;

    /**
     *
     * @param pPosFila
     * @param pPosColumna
     */
    public Coordenada(int pPosFila, int pPosColumna) {
        this.posFila = pPosFila;
        this.posColumna = pPosColumna;
    }

    public int getPosFila() {
        return posFila;
    }

    public void setPosFila(int pPosFila) {
        this.posFila = pPosFila;
    }

    public int getPosColumna() {
        return posColumna;
    }

    public void setPosColumna(int pPosColumna) {
        this.posColumna = pPosColumna;
    }

    public boolean esLinderaTOP(Coordenada pCoordenada) {
        return (this.getPosFila() > 0) ? (this.getPosColumna() == pCoordenada.getPosColumna()
                && this.getPosFila() - 1 == pCoordenada.getPosFila()) : false;
    }

    public boolean esLinderaLEFT(Coordenada pCoordenada) {
        return (this.getPosColumna() > 0) ? (this.getPosFila() == pCoordenada.getPosFila()
                && this.getPosColumna() - 1 == pCoordenada.getPosColumna()) : false;
    }

    public boolean esLinderaBOTTOM(Coordenada pCoordenada) {
        return (this.getPosColumna() == pCoordenada.getPosColumna()
                && this.getPosFila() + 1 == pCoordenada.getPosFila());
    }

    public boolean esLinderaRIGHT(Coordenada pCoordenada) {
        return (this.getPosFila() == pCoordenada.getPosFila()
                && this.getPosColumna() + 1 == pCoordenada.getPosColumna());
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Coordenada other = (Coordenada) obj;
        if (this.getPosFila() != other.getPosFila()) {
            return false;
        }
        if (this.getPosColumna() != other.getPosColumna()) {
            return false;
        }
        return true;
    }

    @Override
    public int compareTo(Coordenada o) {
        int retorno = 0;
        if (this.getPosFila() == o.getPosFila()) {

            if (this.getPosColumna() < o.getPosColumna()) {

                retorno = -1;
            } else {
                if (this.getPosColumna() == o.getPosColumna()) {
                    retorno = 0;
                } else {
                    retorno = 1;
                }
            }
        } else {

            if (this.getPosFila() < o.getPosFila()) {

                retorno = -1;
            } else {
                if (this.getPosFila() == o.getPosFila()) {
                    retorno = 0;
                } else {
                    retorno = 1;
                }
            }
        }
        return retorno;
    }

    @Override
    public String toString() {
        return "Coordenada{" + "posFila=" + this.getPosFila() + ", posColumna=" + this.getPosColumna() + '}';
    }

    @Override
    protected Coordenada clone() throws CloneNotSupportedException {
        return (Coordenada) super.clone(); //To change body of generated methods, choose Tools | Templates.
    }
}
